package com.lanxin.oa.zu.controller;

import com.lanxin.bean.*;
import com.lanxin.oa.zc.service.ZcYiDongService;
import com.lanxin.oa.zu.service.ZuService;
import com.lanxin.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("zu")
public class ZuController {
    @Autowired
    ZuService zuService;
    @RequestMapping("select")
    public ModelAndView selectzcyd(Integer page,Integer pageSize,String type){
        PageBean list=zuService.selectzu(page,pageSize,type);
        ModelAndView mv=new ModelAndView();
        mv.addObject("list",list);
        mv.setViewName("../view/zu/zulist.jsp");
        return mv;
    }
    @RequestMapping("add")
    public ModelAndView selectzcyd(MpCardtype zu){
        zuService.insertzu(zu);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("redirect:select");
        return mv;
    }
    @RequestMapping("toupdate")
    public ModelAndView toupdatezu(Integer oid){
        System.out.println(oid);
        MpCardtype zu=zuService.selectzuByid(oid);
        ModelAndView mv=new ModelAndView();
        mv.addObject("zu",zu);
        mv.setViewName("../view/zu/updatezu.jsp");
        return mv;
    }

    @RequestMapping("type")
    @ResponseBody
    public Map<String,Boolean> checktype(String type, Integer oid){
        Map<String,Boolean> map=new HashMap<String, Boolean>();
        boolean b=zuService.selectByzutype(type,oid);
        if(!b){
            map.put("valid", true);
            return map;
        }
        map.put("valid", false);
        return map;
    }

    @RequestMapping("update")
    public ModelAndView updatezu(MpCardtype zu){
        zuService.updatezu(zu);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("redirect:select");
        return mv;
    }
    @RequestMapping("delete")
    @ResponseBody
    public boolean deletezu(MpCardtype zu){
       return zuService.deletezu(zu);
    }
}
